package br.com.pedro.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
	
	public static SessionFactory sf = buildSessionFactory();
	
	public static SessionFactory buildSessionFactory(){
		try{
			AnnotationConfiguration cfg = new AnnotationConfiguration();
			cfg.configure("hibernate.cfg.xml");
			return cfg.buildSessionFactory();
		}catch(Throwable e){
			System.out.println("Erro do criar session factory.\n Erro: " + e);
			throw new ExceptionInInitializerError(e);
		}
		
	}
	
	public static SessionFactory getSf(){
		return sf;
	}
}



/*package br.com.pedro.util;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	
	public static SessionFactory sf = buildSessionFactory();
	
	public static SessionFactory buildSessionFactory(){
		try{
			Configuration cfg = new Configuration();
			cfg.configure("hibernate.cfg.xml");
			return cfg.buildSessionFactory();
		}catch(Throwable e){
			System.out.println("Erro do criar session factory.\n Erro: " + e);
			throw new ExceptionInInitializerError(e);
		}
		
	}
	
	public static SessionFactory getSf(){
		return sf;
	}
}
*/